﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.IO.Compression;
using System.Collections;

namespace Web.live
{
    public partial class zb : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["sn"]=="1984")
            {
                xqpk.Visible = true;
                MMIP.Visible = true;
                BCBT.Visible = SQBT.Visible = MFBT.Visible = BMFBT.Visible = IPBT.Visible = DIPBT.Visible = SNTB.Visible = zhuce.Visible = true;
                if (!IsPostBack)
                {
                    if (!string.IsNullOrEmpty(Request.QueryString["name"]))
                    {
                        IP.Text = ReadFile(System.Web.HttpContext.Current.Server.MapPath(Request.QueryString["path"] + Request.QueryString["name"]));
                    }
                    else
                    {
                        IP.Text = ReadFile(System.Web.HttpContext.Current.Server.MapPath("/live/ip/") + "ip.html");
                        if (!string.IsNullOrEmpty(Request.QueryString["path"]))
                        {
                            ArrayList AL = LJSheng.Common.FileList.GetAllFilesByFolder(Request.QueryString["path"], "*.html", false);
                            //ArrayList IPAL = LJSheng.Common.FileList.GetAllFilesByFolder("/live/ip/", "*.html", false);
                            if (AL != null)
                            {
                                StringBuilder sb = new StringBuilder();
                                foreach (string li in AL)
                                {
                                    string name = li.Split('\\')[li.Split('\\').Count() - 1];
                                    sb.Append("<li>" + name + " - <a href=\"http://zb.520299.com/live/zb.aspx?sn=1984&path=" + Request.QueryString["path"] + "&name=" + name + "\" target=\"_blank\">读取</a> - <a href=\"http://zb.520299.com" + Request.QueryString["path"] + name + "\" target=\"_blank\">查看</a></li>");
                                }
                                list.InnerHtml = sb.ToString();
                            }
                        }
                    }

                    try
                    {
                        string dypath = System.Web.HttpContext.Current.Server.MapPath("/live/") + "dyidlist.html";
                        FileInfo fi = new FileInfo(dypath);
                        StreamReader sr = new StreamReader(dypath, Encoding.UTF8);
                        string result;
                        ArrayList total = new ArrayList();
                        string dyidpath = System.Web.HttpContext.Current.Server.MapPath("/live/bcdyid.html");
                        //判断文件是否存在
                        if (fi.Exists)
                        {
                            while (!sr.EndOfStream)
                            {
                                result = sr.ReadLine();
                                DDL.Items.Add(result);
                            }
                            sr.Close();
                        }
                        DDL.SelectedValue = ReadFile(dyidpath);
                    }
                    catch (Exception ex) { }
                }
            }
            else if (Request.QueryString["sn"] == "9021616")
            {
                string path = "/live/";
                if (!string.IsNullOrEmpty(Request.QueryString["path"]))
                {
                    path += Request.QueryString["path"] + "/";
                }
                int i = 0;
                ArrayList al = new ArrayList();
                al = LJSheng.Common.FileList.GetAllFilesByFolder(path, false);
                Dictionary<string, DateTime> dic = new Dictionary<string, DateTime>();
                string cw = "------------------错误----------------";
                foreach (string a in al)
                {
                    try
                    {
                        JToken paramJson = JToken.Parse(ReadFile(a));
                        DateTime dt = DateTime.Parse(paramJson["data"]["time"].ToString());
                        dic.Add(a, dt);
                        if (dt >= DateTime.Now && dt.Year != 2088 && dt.Year != 1984)
                        {
                            i++;
                        }
                        if (Request.QueryString["sc"] == "1984" && dt < DateTime.Now)
                        {
                            File.Delete(a);
                        }
                    }
                    catch
                    {
                        dic.Add(a, DateTime.Parse("1984-02-04"));
                        cw += a + "<br />";
                    }
                }
                Response.Write("有效=" + i.ToString() + "<br /><br /><br />");
                var dicSort = from objDic in dic orderby objDic.Value descending select objDic;
                var dicNew = dic.OrderBy(s1 => s1.Value);
                int n = 1;
                foreach (KeyValuePair<string, DateTime> kvp in dicSort)
                {
                    Response.Write("<a href=\"qd\\" + kvp.Key.Split('\\').Last() + "\" target=\"_blank\">" + n.ToString() + "</a>" + "- " + kvp.Key.Split('\\').Last().Split('.').First() + "<a href=\"" + kvp.Key.Split('\\').Last() + "\" target=\"_blank\"> ：</a>" + kvp.Value + "<br />");
                    n++;
                }
                Response.Write(cw);
            }
        }
        /// <summary>
        /// 读取文件
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private string ReadFile(string path)
        {
            string s = "";
            if (File.Exists(path))
            {
                StreamReader myreader = null;
                try
                {
                    myreader = File.OpenText(path);//读取记事本文件
                    s = myreader.ReadToEnd();//从当前位置读取到文件末尾
                }
                catch { s = null; }
                finally
                {
                    if (myreader != null)
                    {
                        myreader.Close();
                        myreader.Dispose();
                    }
                }
            }
            return s;
        }

        private string Encrypt(string encryptString, string encryptKey)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            des.Mode = System.Security.Cryptography.CipherMode.ECB;
            byte[] inputByteArray = Encoding.GetEncoding("UTF-8").GetBytes(encryptString);
            //建立加密对象的密钥和偏移量   
            //原文使用ASCIIEncoding.ASCII方法的GetBytes方法   
            //使得输入密码必须输入英文文本   
            des.Key = ASCIIEncoding.ASCII.GetBytes(encryptKey);
            des.IV = ASCIIEncoding.ASCII.GetBytes(encryptKey);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            StringBuilder ret = new StringBuilder();
            foreach (byte b in ms.ToArray())
            {
                ret.AppendFormat("{0:X2}", b);
            }
            return ret.ToString();
        }

        protected void zhuce_Click(object sender, EventArgs e)
        {
            string diskid = SNTB.Text.Trim();
            if (!string.IsNullOrEmpty(diskid))
            {
                try
                {
                    string czk = RQTB.Text.Trim() + MBTB.Text.Trim().ToUpper();
                    string cz = res(czk + diskid);
                    //充值卡
                    if (string.IsNullOrEmpty(czk))
                    {
                        cz = "";
                    }
                    else
                    {
                        AddCZK(diskid);
                    }
                    SNTB.Text = "";
                    Response.Write(cz);
                }
                catch { }
            }
            else
            {
                Response.Write("请输入密码");
            }
        }


        /// <summary>
        /// 新版授权
        /// </summary>
        /// <param name="diskid"></param>
        /// <param name="czk"></param>
        protected void AddCZK(string diskid)
        {
            try
            {
                string path = System.Web.HttpContext.Current.Server.MapPath("/live/") + diskid + ".html";
                //删除SN文件
                if (SCB.Checked && File.Exists(path))
                {
                    File.Delete(path);
                    //删除远程
                    string url = @"http://182.61.36.5:8888/live/ksapi.ashx?type=dn&sn=" + SNTB.Text.Trim();
                    System.Net.WebClient WebClientObj = new System.Net.WebClient();
                    System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
                    PostVars.Add("dn", diskid);
                    byte[] byRemoteInfo = WebClientObj.UploadValues(url, "POST", PostVars);
                    string sRemoteInfo = System.Text.Encoding.UTF8.GetString(byRemoteInfo);
                    Response.Write(diskid + "-删除成功,远程=" + sRemoteInfo);
                    return;
                }
                ///充值卡
                var bb = new
                {
                    LJSHENG = new
                    {
                        ks = SNTB.Text.Trim(),
                        name = DZTB.Text.Trim(),
                        QQ = !string.IsNullOrEmpty(DZTB.Text.Trim()) ? "QQ:9021616" : ""
                    },
                    linjiansheng = new
                    {
                        dz = !string.IsNullOrEmpty(DZTB.Text.Trim()) ? res(RQTB.Text.Trim() + "DZ" + diskid) : "",
                        pk = KSCB.Checked ? res(RQTB.Text.Trim() + "PK" + diskid) : "",
                        ks = KSHHCB.Checked ? res(RQTB.Text.Trim() + "KS" + diskid) : "",
                        bb = LWCB.Checked ? res(RQTB.Text.Trim() + "BB" + diskid) : "",
                        dh = DYCB.Checked ? res(RQTB.Text.Trim() + "DH" + diskid) : "",
                        dy = DYHHCB.Checked ? res(RQTB.Text.Trim() + "DY" + diskid) : "",
                        hb = HCB.Checked ? res(RQTB.Text.Trim() + "HB" + diskid) : ""
                    },
                    live = new
                    {
                        update = 1,
                        bbh = 2,
                        key = DESEncrypt(RQTB.Text, "ljsheng1")
                    },
                    data = new
                    {
                        pass = LJSheng.Common.RandStr.CreateValidateNumber(6) + "9021616" + LJSheng.Common.RandStr.CreateValidateNumber(8),
                        time = RQTB.Text,
                        msg = QQCB.Checked ? "QQ9021616" : "QQ:9021616"
                    },
                    LD = new
                    {
                        MB = MBCB.Checked ? "9021616" : ""
                    }
                };
                JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                string czk = jsonSerializer.Serialize(bb);

                if (!File.Exists(path))
                {
                    File.Create(path).Close();
                }
                using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
                {
                    sw.Write(czk);
                    sw.Close();
                    sw.Dispose();
                }
                if (WLCB.Checked)
                {
                    ///第三方认证
                    string sjc = LJSheng.Common.LCommon.GetTimeStamp(DateTime.Parse(RQTB.Text.Trim()).AddDays(3));
                    int mm = DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour;
                    if (DSFCB.Checked && KSCB.Checked)
                    {
                        POST(URLTB.Text, "{\"reqmaskcode\":\"" + mm.ToString() + "\",\"authmacid\":\"" + SNTB.Text.Trim() + "\",\"expiredtime\":\"" + sjc + "\",\"authchannel\":\"1\"}");
                    }
                    if (DSFCB.Checked && DYCB.Checked)
                    {
                        POST(URLTB.Text, "{\"reqmaskcode\":\"" + mm.ToString() + "\",\"authmacid\":\"" + SNTB.Text.Trim() + "\",\"expiredtime\":\"" + sjc + "\",\"authchannel\":\"2\"}");
                    }
                    //自动授权
                    //string url = @"http://zb.520299.cn/live/ksapi.ashx?type=ks&sn=" + SNTB.Text.Trim();
                    //System.Net.WebClient WebClientObj = new System.Net.WebClient();
                    //System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
                    //PostVars.Add("czk", czk);

                    //byte[] byRemoteInfo = WebClientObj.UploadValues(url, "POST", PostVars);
                    //string sRemoteInfo = System.Text.Encoding.UTF8.GetString(byRemoteInfo);

                    //阿里云
                    //string ALurl = @"http://zb.9021616.cn/live/ksapi.ashx?type=ks&sn=" + SNTB.Text.Trim();
                    //System.Net.WebClient ALWebClientObj = new System.Net.WebClient();
                    //System.Collections.Specialized.NameValueCollection ALPostVars = new System.Collections.Specialized.NameValueCollection();
                    //ALPostVars.Add("czk", czk);

                    //byte[] ALbyRemoteInfo = ALWebClientObj.UploadValues(ALurl, "POST", ALPostVars);
                    //string ALsRemoteInfo = System.Text.Encoding.UTF8.GetString(ALbyRemoteInfo);
                    //Response.Write(sRemoteInfo);
                }

                PostFWQ("http://live.9021616.cn", czk, 2);
                PostFWQ("http://zb.9021616.cn", czk, 2);
                PostFWQ("http://110.40.159.217:8888", czk, 2);
            }
            catch (Exception err) { Response.Write(err.Message); }
        }

        /// <summary>
        /// 远程服务器
        /// </summary>
        /// <param name="czk"></param>
        private void PostFWQ(string url, string czk, int lx)
        {
            try
            {
                //自动授权
                url = url + "/live/ycczk.ashx?ff=czk&lx=" + lx.ToString() + "&pt=bb&dnid=" + SNTB.Text.Trim();
                System.Net.WebClient WebClientObj = new System.Net.WebClient();
                System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
                PostVars.Add("live", czk);

                byte[] byRemoteInfo = WebClientObj.UploadValues(url, "POST", PostVars);
                //string sRemoteInfo = System.Text.Encoding.UTF8.GetString(byRemoteInfo);

                //阿里云
                //string ALurl = @"http://zb.9021616.cn/live/ycczk.ashx?ff=czk&pt=" + pt + "&dnid=" + SNTB.Text.Trim();
                //System.Net.WebClient ALWebClientObj = new System.Net.WebClient();
                //System.Collections.Specialized.NameValueCollection ALPostVars = new System.Collections.Specialized.NameValueCollection();
                //ALPostVars.Add("live", czk);

                //byte[] ALbyRemoteInfo = ALWebClientObj.UploadValues(ALurl, "POST", ALPostVars);
                //string ALsRemoteInfo = System.Text.Encoding.UTF8.GetString(ALbyRemoteInfo);
                //Response.Write(sRemoteInfo);
            }
            catch { }
        }

        #region DESEnCode DES加密
        //默认密钥向量
        private static byte[] Keys = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 };
        /// <summary>
        /// DES加密字符串
        /// </summary>
        /// <param name="encryptString">待加密的字符串</param>
        /// <param name="encryptKey">加密密钥,要求为8位</param>
        /// <returns>加密成功返回加密后的字符串，失败返回源串</returns>
        public static string DESEncrypt(string encryptString, string encryptKey)
        {
            try
            {
                byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey);
                byte[] rgbIV = Keys;
                byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
                DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Convert.ToBase64String(mStream.ToArray());
            }
            catch
            {
                return null;
            }
        }
        #endregion

        public string res(string es)
        {
            //<RSAKeyValue><Modulus>r8l3eiVWgQLo/kmt1mmMLAT8EUV3vE6TgKxkJV5yq5BvwrOGvpa7EoSSAFHrQsYBoi228TT0riE0mN+P6/gYFuAb1E29GYInbvH+aPouVQdAaNVBmAqmQOM/lAgKGxU6H+PHYtj5YnnmfwJR4jYb0RnmV3u8XSpNKv1KtGt1Ojk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>
            LJSheng.Common.RSA rsa = new LJSheng.Common.RSA();
            string pubkey = @"<RSAKeyValue><Modulus>r8l3eiVWgQLo/kmt1mmMLAT8EUV3vE6TgKxkJV5yq5BvwrOGvpa7EoSSAFHrQsYBoi228TT0riE0mN+P6/gYFuAb1E29GYInbvH+aPouVQdAaNVBmAqmQOM/lAgKGxU6H+PHYtj5YnnmfwJR4jYb0RnmV3u8XSpNKv1KtGt1Ojk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
            return rsa.Encrypt(pubkey, es);
        }
        /// <summary>
        /// 产生RSA的密钥
        /// </summary>
        /// <param name="xmlKeys">私钥</param>
        /// <param name="xmlPublicKey">公钥</param>
        public void RSAKey(out string xmlKeys, out string xmlPublicKey)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            xmlKeys = rsa.ToXmlString(true);
            xmlPublicKey = rsa.ToXmlString(false);
        }

        public string POST(string url, string postdata)
        {
            try
            {
                byte[] byteArray = System.Text.Encoding.UTF8.GetBytes("");
                HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create(url); //发送地址
                byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(postdata);
                objWebRequest.Method = "POST";//提交方式
                objWebRequest.ContentType = "application/json";
                objWebRequest.ContentLength = requestBytes.Length;
                using (Stream newStream = objWebRequest.GetRequestStream())
                {
                    newStream.Write(requestBytes, 0, requestBytes.Length); //写入参数
                    newStream.Close();
                }
                HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();//获取响应
                StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
                return sr.ReadToEnd(); // 返回的数据
            }
            catch (Exception err) { return "http://520299.com"; }
        }

        /// <summary>
        /// 获得post请求后响应的数据
        /// </summary>
        /// <param name="postUrl">请求地址</param>
        /// <param name="referUrl">请求引用地址</param>
        /// <param name="data">请求带的数据</param>
        /// <returns>响应内容</returns>
        public string WFPost(string postUrl, string data)
        {
            string result = "";
            data = Server.UrlEncode(data);
            try
            {
                //命名空间System.Net下的HttpWebRequest类
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);
                //参照浏览器的请求报文 封装需要的参数 这里参照ie9
                //浏览器可接受的MIME类型
                request.Accept = "text/plain, */*; q=0.01";
                //包含一个URL，用户从该URL代表的页面出发访问当前请求的页面
                //request.Referer = referUrl;
                //浏览器类型，如果Servlet返回的内容与浏览器类型有关则该值非常有用
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
                request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                //请求方式
                request.Method = "POST";
                //是否保持常连接
                request.KeepAlive = false;
                request.Headers.Add("Accept-Encoding", "gzip, deflate");
                //表示请求消息正文的长度
                request.ContentLength = data.Length;
                Stream postStream = request.GetRequestStream();
                byte[] postData = Encoding.UTF8.GetBytes(data);
                //将传输的数据，请求正文写入请求流
                postStream.Write(postData, 0, postData.Length);
                postStream.Dispose();
                //响应
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                //判断响应的信息是否为压缩信息 若为压缩信息解压后返回
                if (response.ContentEncoding == "gzip")
                {
                    MemoryStream ms = new MemoryStream();
                    GZipStream zip = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
                    byte[] buffer = new byte[1024];
                    int l = zip.Read(buffer, 0, buffer.Length);
                    while (l > 0)
                    {
                        ms.Write(buffer, 0, l);
                        l = zip.Read(buffer, 0, buffer.Length);
                    }
                    ms.Dispose();
                    zip.Dispose();
                    result = Encoding.UTF8.GetString(ms.ToArray());
                }
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected void DIPBT_Click(object sender, EventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("/live/ip/") + "ip.html", false, Encoding.UTF8))
            {
                sw.Write("");
                sw.Close();
                sw.Dispose();
            }
        }
        private void WFile(string path, string txt)
        {
            using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
            {
                sw.Write(txt);
                sw.Close();
                sw.Dispose();
                Response.Write(txt + "\r\n\r\n\r\n");
            }
            //if (File.Exists(path))
            //{
            //    FileStream stream = new FileStream(path, FileMode.Create);//fileMode指定是读取还是写入
            //    StreamWriter writer = new StreamWriter(stream, Encoding.Default);
            //    writer.Write(txt);//写完后不会换行
            //    writer.Close();//释放内存
            //    stream.Close();//释放内存
            //    //保存文件时没有指定编码格式，所以出现了乱码，只要在StreamWriter writer = new StreamWriter(stream, Encoding.Default); 指定了编码为Encoding.Default文件乱码的问题就解决了
            //    Response.Write(txt);
            //}
        }
        protected void IPBT_Click(object sender, EventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("/live/ip/") + "ip.html", false, Encoding.UTF8))
            {
                sw.Write(IP.Text);
                sw.Close();
                sw.Dispose();
            }
        }

        protected void MFBT_Click(object sender, EventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("/live/ks/") + "mf.html", false, Encoding.UTF8))
            {
                sw.Write("QQ9021616");
                sw.Close();
                sw.Dispose();
                Response.Write("开启免费功能");
            }
        }

        protected void BMFBT_Click(object sender, EventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("/live/ks/") + "mf.html", false, Encoding.UTF8))
            {
                sw.Write("");
                sw.Close();
                sw.Dispose();
                Response.Write("关闭免费功能");
            }
        }
        protected void SQBT_Click(object sender, EventArgs e)
        {
            string zcm = ReadFile(System.Web.HttpContext.Current.Server.MapPath("/live/") + SNTB.Text.Trim() + ".html");
            SQTB.Text = zcm;
            try
            {
                JToken paramJson = JToken.Parse(zcm);
                RQTB.Text = paramJson["data"]["time"].ToString();
                if (paramJson["linjiansheng"]["ks"].ToString().Length > 8)
                {
                    KSHHCB.Checked = KSCB.Checked = true;
                }
                if (paramJson["linjiansheng"]["dh"].ToString().Length > 8)
                {
                    DYHHCB.Checked = DYCB.Checked = true;
                }
            }
            catch { }
        }

        protected void BCBT_Click(object sender, EventArgs e)
        {
            WFile(System.Web.HttpContext.Current.Server.MapPath("/live/") + SNTB.Text.Trim() + ".html", SQTB.Text);
        }

        protected void xqpk_Click(object sender, EventArgs e)
        {
            try
            {
                string diskid = SNTB.Text.Trim();
                StringBuilder sb = new StringBuilder();
                if (lmcb.Checked)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                if (zjcb.Checked)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                if (phbcb.Checked)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                if (cjcb.Checked)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                if (xqcb.Checked)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                if (pkcb.Checked)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                if (xqpkcb.Checked)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                if (spxqcb.Checked)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                sb.Append("0000000000");

                string xq = res(sb.ToString() + diskid);
                string cz = Encrypt(czk.Text.Trim() + diskid, "ljsheng1");
                if (string.IsNullOrEmpty(czk.Text.Trim()))
                {
                    cz = "";
                }
                else
                {
                    AddCZK(czk.Text.Trim().Substring(10, 2) + diskid, cz);
                    if (!string.IsNullOrEmpty(MMIP.Text))
                    {
                        string path = System.Web.HttpContext.Current.Server.MapPath("/czk/mm/");
                        string filename = path + diskid + ".html";
                        WFile(filename, MMIP.Text);
                    }
                }
                if (sb.ToString().Contains("1"))
                {
                    AddCZK(diskid, xq);
                }
                else
                {
                    xq = "";
                }
                Response.Write(xq + "\r\n" + cz);
            }
            catch { }
        }

        protected void AddCZK(string diskid, string czk)
        {
            string path = System.Web.HttpContext.Current.Server.MapPath("/czk/");
            string filename = path + diskid + ".html";
            if (WLCB.Checked)
            {
                WFile(filename, czk);
            }

            if (SCB.Checked && File.Exists(filename))
            {
                File.Delete(filename);
            }
        }
    }
}